<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateBalesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('bales', function (Blueprint $table) {
            $table->increments('id');
            $table->string('natures')->comment('货品属性组合');
            $table->smallInteger('stock')->comment('货品库存量');
            $table->smallInteger('attach')->comment('货品附加价格');
            $table->unsignedInteger('goods_id')->comment('所属商品编号');
//            外键约束
//            foreign()方法是当前表中被约束的字段名，references()方法中表示被哪个字段约束，on（）表示约束当前表中字段在哪个数据表，onDelete('cascade')表示如果约束当前表中字段的另一个表中的字段删除时，当前表被约束的字段也会被删除
            $table->foreign('goods_id')->references('id')->on('goods')->onDelete('cascade');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('bales');
    }
}
